/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.orderView.dish;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JDialog;
import javax.swing.JPanel;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.bean.TExePos;
import com.ruipengkj.bean.TOrder;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.component.jdialog.BorderJPanel;
import com.ruipengkj.component.jdialog.IDialog;
import com.ruipengkj.view.orderView.desk.DeskPanel;
import com.ruipengkj.view.orderView.desk.DeskTypePanel;
/**
 * 说明：
 * 更换桌子面板
 */
public class OrderDeskReplace extends IDialog {

	private static final long serialVersionUID = 1L;

	private DeskTypePanel typePanel;// 餐桌类型 面板
	private DeskPanel deskPanel;// 餐桌面板
	
	private int type;//1、点菜界面订单换桌
	public boolean isSuccess = false;
	
	public OrderDeskReplace(int type) {
		super((JDialog)null, "换桌", true);
		this.setSize(800, 600);
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.type = type;
		init();
	}

	private void init() {
		typePanel = new DeskTypePanel() {
			private static final long serialVersionUID = 1L;
			@Override
			// 查询菜品
			public void QueryDesk(String CatalogId) {
				deskPanel.byTypeQueryDesk(CatalogId);
			}
			
			@Override
			protected void setNoDesk() {
				TExePos TExePos = new TExePos();
				TExePos.setName("没有餐桌");
				addDesk(TExePos);
			}
		};

		deskPanel = new DeskPanel() {
			private static final long serialVersionUID = 1L;
			@Override
			//换桌，点击桌子后的回调函数
			public void AddDesk(TExePos TExePos) {
				addDesk(TExePos);
			}
		};

		JPanel mainPanel = new BorderJPanel(new BorderLayout()) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void paintComponent(Graphics g) {
				super.paintComponent(g);
				g.setColor(new Color(234, 99, 0));
				g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1);
			}
		};
		
		mainPanel.setBackground(Color.white);
		deskPanel.setOpaque(false);
		typePanel.setOpaque(false);
		mainPanel.add(typePanel, BorderLayout.NORTH);
		mainPanel.add(deskPanel, BorderLayout.CENTER);
		mainPanel.setCursor(Util.CURSOR_DEFAULT);
		
		this.add(mainPanel);
	}
	
	protected Dimension getTitleSize() {
		return new Dimension(63, 29);
	}
	
	private TOrder tOrder;//订单
	public void showDialog(TOrder tOrder) {
		this.tOrder = tOrder;
		this.setVisible(true);
	}
	
	
	public void addDesk(TExePos TExePos) {
		if (type == 1) {//1、点菜界面订单换桌
			if (Util.showConfirmDialog("确定更换位置至" + TExePos.getName() +"吗") == 0) {
				if (tOrder != null) {
					tOrder.setPosID(TExePos.getPosID());
					isSuccess = true;
					TExePos.setStatus(ApplicationContext.DESK_STATUS2);//餐桌处于消费状态
					try {
						if (TExePos.getPosID() != null && !TExePos.getPosID().equals("")) {
							BuildSpringApplication.getInstance().getTExePosServiceImpl().saveOrUpdateService(TExePos);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					this.dispose();
				}
			}
		}
	}
}
